<?php
require_once("dbconnect.php");
session_start();


			
//checking a file extention then running the function and original file code copying to original folder

if($_FILES['image_1']['type'] == "image/pjpeg" OR $_FILES['image_1']['type'] == "image/jpeg" OR $_FILES['image_1']['type'] == "image/gif")

		{
			$banner_path="../uploaded/photo_gallery/full_photo/";
			copy($_FILES['image_1']['tmp_name'],$banner_path.$_FILES['image_1']['name']);
		
//end of original file code copying to original folder			
		
// This is the temporary file created by PHP
$uploadedfile = $_FILES['image_1']['tmp_name'];

// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);


// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);


// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
if ($width > $height){
$newwidth = 90;
$newheight=($height/$width)*90;
$tmp=imagecreatetruecolor($newwidth,$newheight);
}else{
$newheight=90;
$newwidth=($width/$height)*90;
$tmp=imagecreatetruecolor($newwidth,$newheight);
}


//watermark code start here - purab is writing
// Create some colors
$white = imagecolorallocate($src, 255, 255, 255);
$grey = imagecolorallocate($src, 128, 128, 128);
$black = imagecolorallocate($src, 0, 0, 0);
//imagefilledrectangle($tmp, 0, 0, 399, 29, $white);

// The text to draw
$text = 'www.eParinay.com';
// Replace path by your own font path
$font = 'ENGA8022.TTF';

// Add some shadow to the text
// imagettftext  ( resource $image  , float $size  , float $angle  , int $x  , int $y  , int $color  , string $fontfile  , string $text  )
#imagettftext($src, $font_size, 0, 11, 61, $grey, $font, $text);

// Add the text
#imagettftext($src, $font_size, 0, 10, 60, $white, $font, $text);
 
// watermark code end here- purab

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);


// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "../uploaded/photo_gallery/thumb/". $_FILES['image_1']['name'];
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
// has completed.

// insert file in mysql and sucessufl message page refresh code and goes to photo upload
$album = $_POST['album_type'];
$fileanme1 = $_FILES['image_1']['name'];
			$sql="INSERT INTO `eparinay`.`photo_album` (`id` ,`album_type` ,`image`)VALUES (NULL , '$album', '$fileanme1')";	
			

				mysql_query($sql);
				 
				 echo "<b><center><font color = red ><h5>Your image Submittied in database Sucessfully<br> If you want to see uploaded photo refresh page</center></b></font></h5>";

			// }

			$t += 1;

			} else {

			$mesg .= "&nbsp;Provided image file type not supported!<BR>";

		}
?>
<html>
<head>
<title>Logout eParinay.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV=Refresh CONTENT="1; URL=create_photo_gallery.php?refresh=1">
<link href="stylesheet/eparinay.css" type="text/css" rel="stylesheet" />
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
	<h1><br />Please wait for moment!</h1><h3>Redirecting...</h3>
</body>
</html>